
// http://www.sonicspot.com/guide/midifiles.html
// http://www.omega-art.com/midi/mfiles.html


#ifndef SEQUENCE_H
#define	SEQUENCE_H

#include <vector>
#include <stdexcept>
#include "track.h"

namespace MidiFile {

enum MidiFormat {
    SingleTrack,
    MultipleSimultaneous,
    MultipleIndependent
};

enum DivisionType {
    TicksPerBeat,
    FramesPerSecond
};

class MIDIFILE_DLL Sequence {
public:

    Sequence() throw () : isLoaded(false)
    {
    }
    Sequence(const char *fileName) throw (FileException, std::bad_alloc);
    Sequence(const Sequence &other) throw (std::bad_alloc);
    ~Sequence() throw ();

    MidiFormat getFormat() const throw (NotLoadedException);
    DivisionType getDivisionType() const throw (NotLoadedException);
    unsigned short getNumTracks() const throw (NotLoadedException);
    unsigned short getTicksPerBeat() const throw (NotLoadedException, InvalidException);
    unsigned char getFramesPerSecond() const throw (NotLoadedException, InvalidException);
    unsigned char getTicksPerFrame() const throw (NotLoadedException, InvalidException);

    inline Track & getTrack(unsigned short idTrack) throw (std::out_of_range)
    {
        return *tracks.at(idTrack);
    }

    void readFile(const char *fileName) throw (FileException, std::bad_alloc);

private:
    bool isLoaded;
    unsigned short format;
    DivisionType divisionType;
    unsigned short ticksPerBeat;
    unsigned char framesPerSecond;
    unsigned char ticksPerFrame;
    std::vector<Track*> tracks;

    void unloadTracks();
};
}

#endif	/* SEQUENCE_H */

